package com.eqdd.yiqidian.ui.companyspace.base

import android.content.Intent
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimImageSelectBean
import com.eqdd.yiqidian.kotlin.BaseAddActivity
import com.eqdd.yiqidian.utils.ImageUtil
import com.eqdd.yiqidian.utils.PicUtil
import com.luck.picture.lib.PictureSelector
import com.luck.picture.lib.config.PictureConfig
import kotlinx.android.synthetic.main.list_item_23.*

/**
 * Created by jhj on 18-6-26.
 */
abstract class BaseSpaceAddActivity : BaseAddActivity() {
    open val isHasImg: Boolean = true
    open val imgIndex : Int = 0

    override fun itemClick(p: Int) {

    }

    override fun initData() {
        super.initData()
        slimAdapterEx.register(R.layout.layout_image_selected, SlimInjector<SlimImageSelectBean> { data, injector ->
            injector?.text(R.id.tv_label, data?.title)
                    ?.clicked(R.id.iv_add) {
                        PicUtil.single(this@BaseSpaceAddActivity, true)
                    }
        })

    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (isHasImg && resultCode == RESULT_OK && requestCode == PictureConfig.CHOOSE_REQUEST) {
            val localMedias = PictureSelector.obtainMultipleResult(data)
            ImageUtil.setImage(localMedias?.get(0)?.compressPath, iv_add)
            slimAdapterEx.getDataItem(imgIndex).tag = localMedias?.get(0)?.compressPath
        }
    }

}